<?php

class administrator extends MX_Controller {

    function __construct() {
        parent::__construct();
    }

    function index() {
        $this->user->check_permission();
        
        $data['view'] = 'administrator_index';
        $this->load->view('template', $data);
    }

    function login() {
        if ($this->input->post('username')) {
            $username = $this->input->post('username');
            $pass = $this->input->post('password');

            $user = $this->user->authen($username, $pass);
            if (isset($user) && $user != null) {
                $userdata = array(
                    'username' => $username,
                    'display_name' => $user->displayname,
                    'logined' => TRUE
                );
                $this->session->set_userdata($userdata);

                redirect('administrator');
            } else {
                $this->session->set_flashdata('login_error', TRUE);
                redirect('administrator/login');
            }
        }
        $this->load->view('administrator_login');
    }
    
    function logout(){
        $this->session->sess_destroy();
        redirect('administrator/login');
    }

}

?>
